<?php
	include_once 'autoload.php';
	

	session_start();

	$ctl = new JoblistCtl();
	$ctl->checkLogged();
	$ctl->checkNotReadonly();
	$ctl->proceed();
	
	$header = new Header();
	$header->render('Job List');
	
	// getting the form and proceed
	$form = $ctl->getJoblistForm();
	$jobs = $form->getJobs();
	
	$selected = $form->getSelected();
	$selected = is_array($selected) ? $selected : array();
?>
<form method="post">
<input type="hidden" name="pagename" value="joblist" id="pgid">
<input type="hidden" name="metname" value="" id="metid">
<input type="hidden" name="idedit" value="" id="idedit">

<h2>Job List </h2>
<p>&nbsp;  </p>
<table cellpadding="4" cellspacing="0" class="list">
  <tr>
    <td>&nbsp;</td>
    <td>Name</td>
    <td>Status</td>
    <td>Download</td>
    <td>Edit</td>
    <td>List</td>
  </tr>
<?php 
	foreach($jobs as $job){
		$name = htmlspecialchars($job->getName());
		$id = $job->getId();
		$status = htmlspecialchars($job->getStatus());
		$sel = array_key_exists($id, $selected);
		$check = HtmlUtil::getCheckbox('selected[]', $id, $sel, array());
		
		// check to see if the file is there
		$folder = PictureConfig::$CONTENT_FOLDER;
		
		$file = "{$folder}/jobs/job_{$id}.dat";
		$visible = is_file($file);
?>
  <tr>
    <td><?php echo $check; ?></td>
    <td nowrap><?php echo $name; ?></td>
    <td nowrap><?php echo $status; ?></td>
    <td>
    <?php if($visible) {?>
    	<a href="javascript: triggeredit('<?php echo $id; ?>', 'download');">Download</a>
	<?php }?>
    </td>
    <td><a href="javascript: triggeredit('<?php echo $id; ?>', 'edit');">Edit</a></td>
    <td><a href="javascript: triggeredit('<?php echo $id; ?>', 'selectlist');">List</a></td>
  </tr>
<?php 
	}
?>
</table>
<p>
  <input type="button" value="Delete" onclick="doConfirm('do you really want to delete the job(s)?', 'delete')">
  <input type="button" value="Add" onclick="triggerform('add')">
</p>
</form>
<?php
	$footer = new Footer();
	$footer->render();
?>
